﻿using System;

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web.Security;
using System.Web.Profile;

using Gift.Model;
using Gift.Model.ENUM;
using Gift.DAL;
using System.Data;


    public partial class admin_login : System.Web.UI.Page
    {

        readonly DALAdminLogin theAdminLogin = new DALAdminLogin();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                Session.Clear();
                string sSource = fun.geturl("");

            }
        }

 
        protected void Button1_Click(object sender, ImageClickEventArgs e)
        {
           
            if (Session["checkCode"] == null ||  string.Compare(Session["checkCode"].ToString(), this.txtCheckCode.Text.ToUpper(), true) != 0)
            {
                base.Response.Write("<script language=javascript>alert('验证码错误，请重新输入！');window.location.href='login.aspx';</script>");
            }
            else
            {
                if (this.ddlUserType.SelectedItem.Value == "1")
                {
                    Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["ERPURL"]
                                   + "?user=" + Gift.Security.DESEncrypt.Encrypt(re.replace(this.txtName.Text.Trim()))
                                   + "&pwd=" + Gift.Security.DESEncrypt.Encrypt(re.replace(this.txtPwd.Text.Trim())));

                }
                else
                {
                    Session.Clear();
                    string usn = re.replace(this.txtName.Text);
                    string pwd = re.EncodeMD5(this.txtPwd.Text.Trim());
                    bool isLogin = login.lo(usn, pwd);

                    if (isLogin)
                    {
                        this.Session["Adminlogin"] = usn;
                        try
                        {
                            this.Session["inphoneNumber"] = theAdminLogin.GetInphoneNumberByName(usn);
                        }
                        catch { }
                        this.Session.Timeout = 60;
                        Response.Redirect("index.aspx");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("<script>alert('用户名或密码错误');</script>");
                    }
                }

            }
        }
    }
